<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <el-form
        label-width="130px"
        :model="subjectForm"
        style="padding-right: 30px;"
        :rules="subjectInfosrules"
        ref="subjectForm"
      >

        <el-row>
          <el-col :span="11" style="margin-top: 27px;">
            <el-form-item class="form-item" label="模版名称 :" prop="name">
              <el-input v-model="subjectForm.name" placeholder="请输入模版名称"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-form-item class="form-item" label="模版描述 :" prop="description">
              <el-input
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 4}"
                placeholder="请输入模版描述"
                v-model="subjectForm.description"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-col :span="20">
              <el-form-item class="form-item" label="类别 :" prop="category">
                <el-select
                  v-model="subjectForm.category"
                  placeholder="请选择"
                  style="width: 280px;"
                >
                  <el-option
                    v-for="item in natureDIC"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-col :span="20">
              <el-form-item label="责任部门:" prop="leadDeptId" class="form-item">
                <span style="font-size: 16px">{{subjectForm.orgName}}</span>
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div class="form-submit">
        <el-button type="warning" @click.stop="commitList()">修改</el-button>
        <el-button type="info" @click.stop="goBack()">关闭</el-button>
      </div>
    </div>
  </basic-container>
</template>

<script>
  import {pimRules} from "@/const/infoRules";
  import {modelDetail,editModel} from "@/api/pim/pim";
  export default {
    name: "editModel",
    created(){
      this.subjectForm.id = this.$route.params.id
      modelDetail(this.$route.params.id).then(response => {
        if (response.data.code == "0") {
          var records = response.data.data;
          this.subjectForm = records;
          this.subjectForm.orgName=this.subjectForm.leadDeptName
        }
      });
    },
    data(){
      return{
        headerData:{
          title:'修改模版'
        },
        subjectInfosrules:pimRules,// 表单验证
        subjectForm: {
          pmuc:'',
        },
        xieorgCodeVisiblesubmit:false,//协同部门树弹窗标志
        natureDIC:[
          {
            label:'指标',
            value:'1'
          },
          {
            label:'任务',
            value:'2'
          },
          {
            label:'项目',
            value:'3'
          },
        ]
      }
    },
    methods:{
      goBack() {
        this.$router.go(-1);
      },
      commitList(){
        this.$confirm("确定修改模版?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$refs.subjectForm.validate(valid => {
            if (valid) {
              editModel(this.subjectForm).then(response => {
                if (response.data.code == 0) {
                  this.$notify({
                    title: "成功",
                    message: "修改成功",
                    type: "success",
                    duration: 2000
                  });
                  this.$router.go(-1);
                }
              })
            }
          })
        })

      }
    }
  }
</script>

<style lang="scss" scoped>
  .card-border {
    border: 1px solid #d2d2d2;
    padding: 12px;
  }
  .form-submit {
    text-align: center;
  }
</style>
